package com.lizhivscaomei.wms.application.service.other;

import com.lizhivscaomei.wms.domain.entity.bills.inout.common.bill.StockBillPassedEvent;
import com.lizhivscaomei.wms.domain.entity.bills.inout.other.in.OtherInBill;
import com.lizhivscaomei.wms.domain.entity.bills.inout.other.in.OtherInBillRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

/**
 * 其他出入库应用服务
 */
@Service
public class OtherInBillManager {
    @Autowired
    private OtherInBillRepo otherInBillRepo;
    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    public OtherInBill create() {
        return new OtherInBill();
    }

    public void save(OtherInBill bill) {
        this.otherInBillRepo.save(bill);
    }

    public void submit(OtherInBill bill) throws Exception {
        bill.submit();
        this.otherInBillRepo.save(bill);
    }

    public void with(OtherInBill bill) throws Exception {
        bill.withdraw();
        this.otherInBillRepo.save(bill);
    }

    public void reject(OtherInBill bill) throws Exception {
        bill.reject();
        this.otherInBillRepo.save(bill);
    }

    public void pass(OtherInBill bill) throws Exception {
        bill.pass();
        this.otherInBillRepo.save(bill);
        //发布审核事件
        this.applicationEventPublisher.publishEvent(new StockBillPassedEvent(this, bill));
    }
}
